public class Solution {
    /*动态规划*/
    public int maxSubArray(int[] nums) {
        int len = nums.length;
        int[] dp = new int[len + 1];
        dp[0] = 0; // 初始条件
        int res = Integer.MIN_VALUE; // 注意最小和最大int的表示
        for (int i = 0; i < len; ++i) {
            if(dp[i] > 0) {
                dp[i+1] = dp[i] + nums[i];

            } else {
                dp[i+1] = nums[i];
            }
            if (dp[i+1] > res) {
                res = dp[i+1];
            }
        }
        return res;
    }
}
